// 对比前str是否包含后substr
function containsSubstring(str, substr) {
  const regex = new RegExp(substr);
  return regex.test(str);
}

function formatDateMonth(date) {
    let date1 = new Date(date)
    const year = date1.getFullYear();
    const month = (date1.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需要加1
    const day = date1.getDate().toString().padStart(2, '0');
    return `${year}-${month}`;
}

function saveToMarkdownFileAndDownload(markdownContent, fileName){
  const blob = new Blob([markdownContent], { type: 'text/markdown' });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.setAttribute('download', `${fileName}.md`);
            link.style.visibility = 'hidden';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
}

export{containsSubstring,formatDateMonth,saveToMarkdownFileAndDownload}
